﻿using MediatR;
using MeetingRoomBooking.Application.Bookings.Commands;
using MeetingRoomBooking.Application.Bookings.Queries;
using MeetingRoomBooking.Application.Rooms.Commands;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers;

[Route("api/[controller]")]
[ApiController]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class BookingController : ControllerBase
{
    private readonly IMediator _mediator;

    public BookingController(IMediator mediator)
    {
        _mediator = mediator;
    }

    [HttpGet]
    [Route("bookings")]
    public async Task<List<BookingViewModel>> GetBookings()
    {
        return await _mediator.Send(new GetBookingQuery());
    }

    [HttpGet]
    [Route("bookings/{userId}")]
    public async Task<List<BookingViewModel>> GetBookingByUserId(int userId)
    {
        return await _mediator.Send(new GetBookingByUserIdQuery { UserId = userId });
    }

    [HttpPost]
    [Route("create")]
    public async Task<int> CreateBooking([FromBody] CreateBookingCommand command)
    {
        return await _mediator.Send(command);
    }

    [HttpPut]
    [Route("update")]
    public async Task EditBooking([FromBody] UpdateBookingCommand command)
    {
        await _mediator.Send(command);
    }
    [HttpDelete]
    [Route("bookings/{id}")]
    public async Task Booking(int id)
    {
        var command = new DeleteBookingCommand { Id = id };

        await _mediator.Send(command);
    }
}
